package com.ruoyi.business.webapi.controller;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.mysqldump.service.IBizProjectInfoService;
import com.ruoyi.mysqldump.vo.BizProjectInfoVo;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 项目管理Controller
 *
 * @author Tellsea
 * @date 2022-02-11
 */
@Api(value = "项目管理控制器", tags = {"项目管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mysqldump/projectInfo")
public class BizProjectInfoController extends BaseController {

    private final IBizProjectInfoService iBizProjectInfoService;

    @ApiOperation("查询项目管理列表")
    @PreAuthorize("@ss.hasPermi('mysqldump:projectInfo:list')")
    @GetMapping("/list")
        public TableDataInfo<BizProjectInfoVo> list(BizProjectInfoVo entity) {
        return iBizProjectInfoService.queryList(entity);
    }

    @ApiOperation("导出项目管理列表")
    @PreAuthorize("@ss.hasPermi('mysqldump:projectInfo:export')")
    @Log(title = "项目管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<BizProjectInfoVo> export(@Validated BizProjectInfoVo entity) {
        List<BizProjectInfoVo> list = iBizProjectInfoService.queryList(entity).getRows();
        ExcelUtil<BizProjectInfoVo> util = new ExcelUtil<BizProjectInfoVo>(BizProjectInfoVo.class);
        return util.exportExcel(list, "项目管理");
    }

    @ApiOperation("获取项目管理详细信息")
    @PreAuthorize("@ss.hasPermi('mysqldump:projectInfo:query')")
    @GetMapping("/getInfo/{id}")
    public AjaxResult<BizProjectInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                              @PathVariable("id") Long id) {
        return AjaxResult.success(iBizProjectInfoService.queryById(id));
    }

    @ApiOperation("新增项目管理")
    @PreAuthorize("@ss.hasPermi('mysqldump:projectInfo:add')")
    @Log(title = "项目管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping("add")
    public AjaxResult<Void> add(@Validated @RequestBody BizProjectInfoVo entity) {
		entity.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
        return toAjax(iBizProjectInfoService.save(entity) ? 1 : 0);
    }

    @ApiOperation("修改项目管理")
    @PreAuthorize("@ss.hasPermi('mysqldump:projectInfo:edit')")
    @Log(title = "项目管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping("edit")
    public AjaxResult<Void> edit(@Validated @RequestBody BizProjectInfoVo entity) {
        return toAjax(iBizProjectInfoService.updateById(entity) ? 1 : 0);
    }

    @ApiOperation("删除项目管理")
    @PreAuthorize("@ss.hasPermi('mysqldump:projectInfo:remove')")
    @Log(title = "项目管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                   @PathVariable Long[] ids) {
        return toAjax(iBizProjectInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
